<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="mini" label-width="68px">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="项目区域" prop="projectRegion">
            <el-select v-model="queryParams.projectRegion" placeholder="请选择" clearable
              @keyup.enter.native="handleQuery">
              <el-option v-for="dict in dict.type.cld_project_region" :key="dict.value" :label="dict.label"
                :value="parseInt(dict.value)"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="项目名称" prop="projectName">
            <el-input v-model="queryParams.projectName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="员工姓名" prop="staffName">
            <el-input v-model="queryParams.staffName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="统计月份" prop="month">
            <el-date-picker v-model="queryParams.month" type="month" placeholder="选择月">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="attendanceList" border>
      <el-table-column label="项目区域" align="center" prop="projectRegion">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_region" :value="scope.row.projectRegion" />
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="员工编号" align="center" prop="staffNo" />
      <el-table-column label="员工姓名" align="center" prop="staffName" />
      <el-table-column label="性别" align="center" prop="staffSex" />
      <el-table-column label="年龄" align="center">
        <template slot-scope="scope">
          <span>{{ calculateAge(scope.row.staffIdcard) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="岗位" align="center" prop="projectPostName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_post" :value="scope.row.projectPostName" />
        </template>
      </el-table-column>
      <el-table-column label="组别" align="center" prop="groupName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_groups" :value="scope.row.groupName" />
        </template>
      </el-table-column>
      <el-table-column label="应出勤天数" align="center" prop="echoCount" />
      <el-table-column label="实出勤天数" align="center" prop="realCount" />
      <el-table-column label="加班天数" align="center" prop="overtimeCount" />
      <el-table-column label="请假天数" align="center" prop="leaveCount" />
      <el-table-column label="补卡次数" align="center" prop="replaceCount" />
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { selectAttendanceStatisticsList } from "@/api/cld/attendance";

export default {
  name: "Attendance",
  dicts: ['cld_project_region', 'cld_project_post', 'cld_project_groups'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 考勤打卡表格数据
      attendanceList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectRegion: null,
        projectName: null,
        staffName: null,
        attendanceYear: null,
        attendanceMonth: null,
        month: null
      },
      dateRange: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询考勤打卡列表 */
    getList() {
      this.loading = true;
      selectAttendanceStatisticsList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.attendanceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if (this.queryParams.month) {
        this.queryParams.attendanceYear = this.parseTime(this.queryParams.month, '{y}')
        this.queryParams.attendanceMonth = this.parseTime(this.queryParams.month, '{m}')
      }
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams.attendanceYear = null;
      this.queryParams.attendanceMonth = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
<style scoped>
.el-range-editor.el-input__inner {
  width: 100%;
}

.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}

.el-select {
  width: 100%;
}
</style>
